﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Resources;

using ForexHistory;

namespace CommonUnitTests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class TickRetrieval
    {
        CurrencyHistoryManager _manager;
        private const string resxFile = @".\TestResources.resx";
        public TickRetrieval()
        {

            _manager = new CurrencyHistoryManager();
            _manager.Start = 2008;
            _manager.End = 2008;

            _manager.LoadGBPUSD = true;

            _manager.AddFile(TestResources.CurrencyLoadTestFile.ToString());

            _manager.StartLoad();

            while (!_manager.ProcessingComplete)
            { }


            // Retrieve Automobile objects.  
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        //581931915	GBP/USD	2008-06-09 10:44:49	1.9741	1.9745
        //581931929	GBP/USD	2008-06-09 10:44:49	1.9741	1.9746
        //581931915	GBP/USD	2008-06-09 10:44:49	1.9741	1.9745
        //581931929	GBP/USD	2008-06-09 10:44:49	1.9741	1.9744

        [TestMethod]
        public void ExactTimeMatch_MultiplePerSecond()
        {
            DateTime _testTime;

            _testTime = new DateTime(2008, 06, 09, 10, 44, 49);

            // 1

            Tick res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9741m);

            Assert.IsTrue(res.RateAsk == 1.9745m);

            // 2
            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9741m);

            Assert.IsTrue(res.RateAsk == 1.9746m);

            // 3

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9741m);

            Assert.IsTrue(res.RateAsk == 1.9745m);

            // 4
            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9741m);

            Assert.IsTrue(res.RateAsk == 1.9744m);

            _testTime = new DateTime(2008, 06, 09, 10, 45, 07);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9741m);

            Assert.IsTrue(res.RateAsk == 1.9744m);
            // 581932091	GBP/USD	2008-06-09 10:45:08	1.9744	1.9743	D																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																										

            _testTime = new DateTime(2008, 06, 09, 10, 45, 08);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9744m);

            Assert.IsTrue(res.RateAsk == 1.9743m);


            _testTime = new DateTime(2008, 06, 09, 10, 45, 09);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9744m);

            Assert.IsTrue(res.RateAsk == 1.9743m);


            // exact
            //581932151	GBP/USD	2008-06-09 10:45:13	1.9743	1.9748	D																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																										

            _testTime = new DateTime(2008, 06, 09, 10, 45, 13);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9743m);

            Assert.IsTrue(res.RateAsk == 1.9748m);


            //exact
            //581932162	GBP/USD	2008-06-09 10:45:14	1.9744	1.9749	D																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																										


            _testTime = new DateTime(2008, 06, 09, 10, 45, 14);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9744m);

            Assert.IsTrue(res.RateAsk == 1.9749m);																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																	

            // one past

            _testTime = new DateTime(2008, 06, 09, 10, 45, 15);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9744m);

            Assert.IsTrue(res.RateAsk == 1.9749m);																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																	


        }


        [TestMethod]
        public void RandomTimes()
        {


            DateTime _testTime;

            _testTime = new DateTime(2008, 06, 13, 12, 50, 11);

            // 1
            // 583858820,GBP/USD,2008-06-13 12:50:11,1.9488,1.9493,D

            Tick res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9488m);

            Assert.IsTrue(res.RateAsk == 1.9493m);


            _testTime = new DateTime(2008, 06, 13, 12, 52, 11);

            // 1
            // 583859402,GBP/USD,2008-06-13 12:52:12,1.9487,1.9492,D

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9488m);

            Assert.IsTrue(res.RateAsk == 1.9493m);



            _testTime = new DateTime(2008, 06, 13, 12, 52, 12);

            // 1
            // 583859402,GBP/USD,2008-06-13 12:52:12,1.9487,1.9492,D

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9487m);

            Assert.IsTrue(res.RateAsk == 1.9492m);


            _testTime = new DateTime(2008, 06, 13, 12, 52, 13);

            // 1
            // 583859402,GBP/USD,2008-06-13 12:52:12,1.9487,1.9492,D

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9487m);

            Assert.IsTrue(res.RateAsk == 1.9492m);

            _testTime = new DateTime(2008, 06, 13, 12, 52, 24);

            // 1
            // 583859402,GBP/USD,2008-06-13 12:52:12,1.9487,1.9492,D

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9487m);

            Assert.IsTrue(res.RateAsk == 1.9492m);


            _testTime = new DateTime(2008, 06, 13, 12, 52, 25);

            // 583859470,GBP/USD,2008-06-13 12:52:25,1.9486,1.9491,D

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9486m);

            Assert.IsTrue(res.RateAsk == 1.9491m);


            _testTime = new DateTime(2008, 06, 13, 12, 52, 26);

            // 583859470,GBP/USD,2008-06-13 12:52:25,1.9486,1.9491,D

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9486m);

            Assert.IsTrue(res.RateAsk == 1.9491m);



            // 583857272,GBP/USD,2008-06-13 12:46:27,1.9487,1.9492,D

            _testTime = new DateTime(2008, 06, 13, 12, 46, 28);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9487m);

            Assert.IsTrue(res.RateAsk == 1.9492m);

            // 583857345,GBP/USD,2008-06-13 12:46:38,1.9488,1.9493,D

            _testTime = new DateTime(2008, 06, 13, 12, 46, 39);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9488m);

            Assert.IsTrue(res.RateAsk == 1.9493m);


            // 583839942,GBP/USD,2008-06-13 11:56:38,1.949,1.9495,D

            _testTime = new DateTime(2008, 06, 13, 11, 56, 39);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.949m);

            Assert.IsTrue(res.RateAsk == 1.9495m);


            // 583839951,GBP/USD,2008-06-13 11:56:41,1.9491,1.9496,D
            // 583839962,GBP/USD,2008-06-13 11:56:42,1.949,1.9495,D
            _testTime = new DateTime(2008, 06, 13, 11, 56, 43);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.949m);

            Assert.IsTrue(res.RateAsk == 1.9495m);

            // 583839962,GBP/USD,2008-06-13 11:56:42,1.949,1.9495,D

            _testTime = new DateTime(2008, 06, 13, 11, 56, 42);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.949m);

            Assert.IsTrue(res.RateAsk == 1.9495m);

            // 583840106,GBP/USD,2008-06-13 11:57:00,1.9491,1.9496,D

            _testTime = new DateTime(2008, 06, 13, 11, 56, 59);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.949m);

            Assert.IsTrue(res.RateAsk == 1.9495m);

            _testTime = new DateTime(2008, 06, 13, 11, 57, 00);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9491m);

            Assert.IsTrue(res.RateAsk == 1.9496m);

            _testTime = new DateTime(2008, 06, 13, 11, 57, 01);

            res = _manager.GetTick(Common.CurrencyPair.GBPUSD, _testTime);

            Assert.IsTrue(res.RateBid == 1.9491m);

            Assert.IsTrue(res.RateAsk == 1.9496m);


        }

        [TestMethod]
        public void CrossingHours()
        {




        }

        [TestMethod]
        public void CrossingDays()
        {

        }

        [TestMethod]
        public void CrossingWeeks()
        {

        }

        [TestMethod]
        public void CrossingMonths()
        {

        }

        [TestMethod]
        public void CrossCurrency()
        {

        }
    }
}
